<?php
namespace app\index\controller;
use think\Controller;
use Common\Controller\BaseController;
use think\Request;
use think\Session;
class bankcard extends Controller
{
    public function bankcard(){
        $user = session('member');
        if(!$user) {
            header("Location:../../index/login/login");
        }
        $memberid['memberid'] = session('member.id');
        //dump($memberid);exit;
        $res = db('bankcard')->where($memberid)->select();
        $this->assign('list',$res);
        return $this->fetch();
    }
    public function bankcard_ins(){
        $user = session('member');
        if(!$user) {
            header("Location:../../index/login/login");
        }
        return $this->fetch();
    }
    public function bankcard_insa(){
        $user = session('member');
        if(!$user) {
            header("Location:../../index/login/login");
        }
        return $this->fetch();
    }
    public function bankcardadd(){
        $user = session('member');
        if(!$user) {
            header("Location:../../index/login/login");
        }
        if(!$_POST){
            return ['code' => 0, 'msg' => '提交不能为空'];
        }
        $data['name'] = trim(input('name'));
        $cardnumber['cardnumber'] = $data['cardnumber'] = trim(input('cardnumber'));
        $data['cardholder'] = trim(input('cardholder'));
        $data['memberid'] = session('member.id');
        $re = db('bankcard')->where($cardnumber)->find();
        if($re){
            return ['code' => 3, 'msg' => '此卡已添加'];
        }
        $res = db('bankcard')->insert($data);
        if($res){
            return ['code' => 1, 'msg' => '添加成功'];
        }else{
            return ['code' => 2, 'msg' => '添加失败'];
        }
    }
}